import time
import requests
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By

import ddddocr
ocr = ddddocr.DdddOcr(show_ad=False, beta=True)

service = Service(executable_path="D:\\chromedriver.exe")

driver = webdriver.Chrome(service=service)
driver.implicitly_wait(5)

driver.get("https://www.labnetwork.com.cn/login")

email_input = driver.find_element(By.XPATH, '//input[@placeholder="请输入邮箱"]')
email_input.send_keys("496575233@qq.com")

password_input = driver.find_element(By.XPATH, '//input[@placeholder="请输入密码"]')
password_input.send_keys("pckzzy101")


while True:
	time.sleep(2)
	captcha_code_img = driver.find_element(By.XPATH, '//div[@class="captcha_code"]/img')
	captcha_code_img_bytes = captcha_code_img.screenshot_as_png
	code = ocr.classification(captcha_code_img_bytes)
	print(code, "---------------")


	code_input = driver.find_element(By.XPATH, '//input[@placeholder="验证码"]')
	code_input.clear()
	code_input.send_keys(code)

	submit_btn = driver.find_elements(By.XPATH, '//button[contains(@class, "el-button--primary")]')[0]
	submit_btn.click()

	time.sleep(3)
	try:
		success_info = driver.find_element(By.XPATH, '//h2[contains(text(), "欢迎登录")]')
	except Exception as e:
		print(f"登录成功")
		break

# 进入我的足迹
# driver.get("https://www.labnetwork.com.cn/myfootprint")


time.sleep(1)

# 获取token
token = driver.execute_script("return localStorage.getItem('mallToken')")


# 获取我的足迹
collect_res = requests.post("https://www.labnetwork.com.cn/gateway/basic/mall/footprint/list", json={
    "page": 1,
    "limit": 12,
    "operTimestr": "",
    "productType": 1
}, headers={

    # 用户信息
    "token": token,
    # "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36",
    "referer": "https://www.labnetwork.com.cn/"
})

print(collect_res.json())



